import { create } from 'zustand';
import storeUtil from '@pangza-club/utils/store';


export const userStore = create<IUserStore>((set, get) => ({
    user: {
        nickName: '',
        token: '',
        roles: []
    },
    setUser: (user: LoginVO) => {
        set({ user });
        storeUtil.set('user', user);
    },
    getUser: () => {
        return storeUtil.get('user') || get().user;
    },
    reset: () => {
        set({ user: { nickName: '', token: '', roles: [] } });
        storeUtil.remove('user');
    }
}));